/***********************************************************************
 * Module:  Album.java
 * Author:  Voja
 * Purpose: Defines the Class Album
 ***********************************************************************/

package model;

import java.util.*;

public class Album {
   public int albumId;
   public java.lang.String albumTitle;
   public java.lang.String albumDescription;
   public boolean albumPublic;
   
   public java.util.Collection<Photo> has_photo;
   public java.util.Collection<User> favorites;
   public User user;
   
   
   /** @pdGenerated default getter */
   public java.util.Collection<Photo> getHas_photo() {
      if (has_photo == null)
         has_photo = new java.util.HashSet<Photo>();
      return has_photo;
   }
   
   /** @pdGenerated default iterator getter */
   public java.util.Iterator getIteratorHas_photo() {
      if (has_photo == null)
         has_photo = new java.util.HashSet<Photo>();
      return has_photo.iterator();
   }
   
   /** @pdGenerated default setter
     * @param newHas_photo */
   public void setHas_photo(java.util.Collection<Photo> newHas_photo) {
      removeAllHas_photo();
      for (java.util.Iterator iter = newHas_photo.iterator(); iter.hasNext();)
         addHas_photo((Photo)iter.next());
   }
   
   /** @pdGenerated default add
     * @param newPhoto */
   public void addHas_photo(Photo newPhoto) {
      if (newPhoto == null)
         return;
      if (this.has_photo == null)
         this.has_photo = new java.util.HashSet<Photo>();
      if (!this.has_photo.contains(newPhoto))
      {
         this.has_photo.add(newPhoto);
         newPhoto.addHas_photo(this);      
      }
   }
   
   /** @pdGenerated default remove
     * @param oldPhoto */
   public void removeHas_photo(Photo oldPhoto) {
      if (oldPhoto == null)
         return;
      if (this.has_photo != null)
         if (this.has_photo.contains(oldPhoto))
         {
            this.has_photo.remove(oldPhoto);
            oldPhoto.removeHas_photo(this);
         }
   }
   
   /** @pdGenerated default removeAll */
   public void removeAllHas_photo() {
      if (has_photo != null)
      {
         Photo oldPhoto;
         for (java.util.Iterator iter = getIteratorHas_photo(); iter.hasNext();)
         {
            oldPhoto = (Photo)iter.next();
            iter.remove();
            oldPhoto.removeHas_photo(this);
         }
      }
   }
   /** @pdGenerated default getter */
   public java.util.Collection<User> getFavorites() {
      if (favorites == null)
         favorites = new java.util.HashSet<User>();
      return favorites;
   }
   
   /** @pdGenerated default iterator getter */
   public java.util.Iterator getIteratorFavorites() {
      if (favorites == null)
         favorites = new java.util.HashSet<User>();
      return favorites.iterator();
   }
   
   /** @pdGenerated default setter
     * @param newFavorites */
   public void setFavorites(java.util.Collection<User> newFavorites) {
      removeAllFavorites();
      for (java.util.Iterator iter = newFavorites.iterator(); iter.hasNext();)
         addFavorites((User)iter.next());
   }
   
   /** @pdGenerated default add
     * @param newUser */
   public void addFavorites(User newUser) {
      if (newUser == null)
         return;
      if (this.favorites == null)
         this.favorites = new java.util.HashSet<User>();
      if (!this.favorites.contains(newUser))
      {
         this.favorites.add(newUser);
         newUser.addFavorite(this);      
      }
   }
   
   /** @pdGenerated default remove
     * @param oldUser */
   public void removeFavorites(User oldUser) {
      if (oldUser == null)
         return;
      if (this.favorites != null)
         if (this.favorites.contains(oldUser))
         {
            this.favorites.remove(oldUser);
            oldUser.removeFavorite(this);
         }
   }
   
   /** @pdGenerated default removeAll */
   public void removeAllFavorites() {
      if (favorites != null)
      {
         User oldUser;
         for (java.util.Iterator iter = getIteratorFavorites(); iter.hasNext();)
         {
            oldUser = (User)iter.next();
            iter.remove();
            oldUser.removeFavorite(this);
         }
      }
   }
   /** @pdGenerated default parent getter */
   public User getUser() {
      return user;
   }
   
   /** @pdGenerated default parent setter
     * @param newUser */
   public void setUser(User newUser) {
      if (this.user == null || !this.user.equals(newUser))
      {
         if (this.user != null)
         {
            User oldUser = this.user;
            this.user = null;
            oldUser.removeAlbums(this);
         }
         if (newUser != null)
         {
            this.user = newUser;
            this.user.addAlbums(this);
         }
      }
   }

}